/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.amuthu.expression.function;

import org.amuthu.expression.AbstractExpression;
import org.amuthu.expression.Expression;
import org.amuthu.expression.exception.TypeMismatchException;
import org.amuthu.parser.ExpressionVisitor;

/**
 *
 * @author prabhus
 */
public class FunctionExpression extends AbstractExpression
{
   private int argCount;
   private String name;

   public Expression[] getChildren()
   {
      return children;
   }

   public String getName()
   {
      return name;
   }

   public FunctionExpression(String name, Expression[] children, int argCount)
   {
      super(children);
      this.name = name;
      this.argCount = argCount;
   }

   @Override
   public void accept(ExpressionVisitor visitor)
   {
      visitor.visit(this);
   }

   @Override
   public int checkType() throws TypeMismatchException
   {
      return FLOAT_TYPE;
   }

   @Override
   public int getType()
   {
      return FLOAT_TYPE;
   }

   @Override
   public int getChildCount()
   {
      return argCount;
   }

   @Override
   public String toString()
   {
      String string = name + "(";

      for (int i = 0; i < argCount; i++)
      {
         string += getChild(i).toString();

         if (i != (argCount - 1))
         {
            string += ",";
         }
      }

      string += ")";

      return string;
   }
}
